package com.jdbctest;

import com.example.demo1.pojo.Stu;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.io.InputStream;

public class db {
    @Test
    public void DbTest(){
        /* 读取配置文件*/
        InputStream rs = null;
        try {
            rs = Resources.getResourceAsStream("mybatis-config.xml");
        } catch (IOException e) {
            e.printStackTrace();
        }
        /* sqlSession SqlSessionFactoryBuilder openSession打开会话 执行sql 语句*/
        SqlSessionFactory build = new SqlSessionFactoryBuilder().build(rs);
        /*openSession打开会话  执行sql*/
        SqlSession sqlSession = build.openSession();
        Stu stu = sqlSession.selectOne("findById", "1");
        System.out.println(stu.getNumber());
        System.out.println(stu.getName());
        System.out.println(stu.getBirthday());
        System.out.println(stu.getStu());

        /* 关闭会话*/
        sqlSession.close();

    }
}
